#include <iostream>
using namespace std;

// 68.41 %
class Solution
{
  public:
	bool isPowerOfThree(int n)
	{
		if (n <= 0)
			return false;
		while (n != 1)
		{
			if (n % 3 != 0)
				return false;
			n /= 3;
		}
		return true;
	}
};

int main()
{
	int num = 6;
	cout << Solution().isPowerOfThree(num) << endl;
	return 0;
}